package cn.shyouchi.wuguanjia.android.ui.patrol.begin;

import android.view.View;
import android.widget.TextView;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerPreviewActivity;
import cn.bingoogolapple.photopicker.widget.BGASortableNinePhotoLayout;
import cn.shyouchi.wuguanjia.android.R;
import cn.shyouchi.wuguanjia.android.base.BaseActivity;
import cn.shyouchi.wuguanjia.android.widget.TopBar;

public class PreviewPatrolRingDetailActivity extends BaseActivity implements  BGASortableNinePhotoLayout.Delegate{

    private static final int REQUEST_CODE_CHOOSE_PHOTO = 1;
    private static final int REQUEST_CODE_PHOTO_PREVIEW = 2;

    @BindView(R.id.topBar)
    TopBar mTopBar;
    @BindView(R.id.tv_report_time)
    TextView mTvReportTime;
    @BindView(R.id.tv_report_time_diff)
    TextView mTvReportTimeDiff;
    @BindView(R.id.photo_snpl)
    BGASortableNinePhotoLayout mPhotoSnpl;
    @BindView(R.id.tv_report_content)
    TextView mTvReportContent;

    PatrolRingDesEntity.ResultMessageBean.InfoBean entity;
    ArrayList<String> photos = new ArrayList<>();

    private final String BASE_URL = "http://118.178.88.132:8000";



    @Override
    public int initContentView() {
        return R.layout.activity_preview_patrol_ring_detail;
    }

    @Override
    public void initInjector() {
        entity = getIntent().getParcelableExtra("info");


        for (String s : entity.getImage()) {
            try {
                String p = new JSONObject(s).getString("image");
                photos.add(BASE_URL + p);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    @Override
    public void initUiAndListener() {
        ButterKnife.bind(this);
        mTopBar.setTitle(getTitle().toString());
        mTopBar.setLeftIcon(R.mipmap.ic_back);
        setSupportActionBar(mTopBar.getToolbar());

        mTvReportTime.setText(entity.getInspectiontime());
        mTvReportTimeDiff.setText(entity.getInspectionname());
        mTvReportContent.setText(entity.getInspectioncontent());
        mPhotoSnpl.init(this);
        mPhotoSnpl.setData(photos);
        mPhotoSnpl.setDelegate(this);
    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean isApplyStatusBarColor() {
        return true;
    }

    @Override
    public void onClickAddNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, ArrayList<String> models) {

    }

    @Override
    public void onClickDeleteNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList<String> models) {

    }

    @Override
    public void onClickNinePhotoItem(BGASortableNinePhotoLayout sortableNinePhotoLayout, View view, int position, String model, ArrayList<String> models) {
        startActivityForResult(BGAPhotoPickerPreviewActivity.newIntent(this, mPhotoSnpl.getMaxItemCount(), models, models, position, false), REQUEST_CODE_PHOTO_PREVIEW);
    }


}
